<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <father></father>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        let son = {
            data() {
                return {
                    isShow: false
                }
            },
            methods: {
                showOrHide() {
                    this.isShow = !this.isShow
                }
            },

            template: "<div v-if='isShow'>Son</div>"
        }

        let father = {
            components: {
                son
            },
            data() {
                return {}
            },
            template: "<div>father<button @click='showOrHide'>显示隐藏</button><son ref='myson'></son></div>",
            methods: {
                showOrHide() {
                    // 获取的是Vue组件实例对象
                    // ref加到DOM元素上，获取到的是DOM节点
                    // ref加到组件上,获取到的Vue组件实例
                    console.log(this.$refs.myson)
                    // this.$refs.myson.showOrHide()
                    this.$refs.myson.isShow = !this.$refs.myson.isShow
                }
            }
        }


        const app = new Vue({
            el: "#app",
            components: {
                father
            },
            data() {
                return {}
            }
        })
    </script>
</body>

</html>